package com.hongyang.servlet.midwife;

import com.alibaba.fastjson.JSONObject;
import com.hongyang.entity.Midwife;
import com.hongyang.service.MidwifeService;
import com.hongyang.service.impl.MidwifeServiceImpl;
import com.hongyang.vo.ResultEnum;
import com.hongyang.vo.ResultVO;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = "/hr/hospital/midwife")
public class SearchByHospital extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        //设置编码格式
        req.getParameter("UTF-8");
        res.setCharacterEncoding("UTF-8");
        res.setContentType("text/html;charset=UTF-8");

        ResultVO resultVO=null;

        String hospitalId=req.getParameter("hospitalId");

        if (StringUtils.isBlank(hospitalId)){
            resultVO=ResultVO.failed(ResultEnum.PARAMS_FAILED);
        }else{
            MidwifeService midwifeService=new MidwifeServiceImpl();
            List<Midwife> arr = midwifeService.search(hospitalId);

            resultVO=ResultVO.success(arr);
        }



        PrintWriter writer=res.getWriter();
        String jsonString = JSONObject.toJSONString(resultVO);
        writer.println(jsonString);
        writer.flush();
        writer.close();
    }
}
